<?php
session_start();
//首先检查登录状态。
//var_dump($_COOKIE['hasLoggedUsername']);
if(isset($_COOKIE['hasLoggedUsername']) and $_COOKIE['hasLoggedUsername'] != ""){ //说明上次保存了登录，且在有效期内
    //视为用户登录了
    //也要干登录后的三件事
    $_SESSION['logged'] = 1;
    $_SESSION['username'] = $_COOKIE['hasLoggedUsername'];
    $_SESSION['admin'] = $_COOKIE['isAdmin'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理系统</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <style>
        li {
            list-style: none;
        }

        .row {
            margin: 20px
        }

        .row li {
            text-align: center;
        }

        li {
            margin: 20px
        }

        li a {
            border: 1px solid blue;
            padding: 10px;
        }


        /* 小屏幕（平板，大于等于 768px） */
        @media (min-width: 768px) {
            .row {
                margin: 80px
            }

            li {
                margin: 20px
            }
        }

        @media (min-width: 991px) {
            .row {
                margin: 80px 130px
            }

            li {
                margin: 40px
            }
        }

        @media (min-width: 1199px) {
            .row {
                margin: 80px 260px
            }

            li {
                margin: 20px
            }
        }
    </style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
        integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
        crossorigin="anonymous"></script>
<div class="row">
    <!--判断用户是否已经登录，如果登录了，则显示欢迎信息-->

    <div class="col-md-offset-6 col-md-6 col-xs-offset-3 col-xs-9 " style="text-align: right">
        <?php
    /*if(isset($_SESSION['logged']) and $_SESSION['logged'] == 1){*/
    if ($_SESSION['logged'] == 1) {
        ?>
         欢迎您，<span
                    style="color: red"><?php echo $_SESSION['username']; ?></span>
        <?php
    }
    ?>
        <span id="time"></span> <?php if(isset($_SESSION['logged']) and $_SESSION['logged'] == 1){ ?><a href="logout.php">注销</a><?php } ?>
    </div>
    <div class="col-xs-6 col-sm-4 col-md-3">
        <li><a href="singUp.html">用户注册</a></li>
    </div>
    <div class="col-xs-6 col-sm-4 col-md-3">
        <li><a href="login.html">用户登录</a></li>
    </div>
    <div class="col-xs-6 col-sm-4 col-md-3">
        <li><a href="admin.php">用户管理</a></li>
    </div>
    <div class="col-xs-6 col-sm-4 col-md-3">
        <li><a href="modify.php?username=<?php echo isset($_SESSION['username'])?$_SESSION['username']:'';?>">资料修改</a></li>
    </div>
</div>
<script type="text/javascript">
    function time() {
        var vWeek, vWeek_s, vDay;
        vWeek = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        var date = new Date();
        year = date.getFullYear();
        month = check(date.getMonth() + 1);
        day = check(date.getDate());
        hours = check(date.getHours());
        minutes = check(date.getMinutes());
        seconds = check(date.getSeconds());
        vWeek_s = date.getDay();
        document.getElementById("time").innerHTML = year + "-" + month + "-" + day + " " + "\t" + hours + ":" + minutes + ":" + seconds ;
        setTimeout(time,1000);
    };
    function check(f) {
        var n;
        f < 10 ? n = "0" + f : n = f;
        return n;
    }
    time();
    //setInterval("time()", 1000);
</script>
</body>
</html>
